package com.play.ballen.mall.adapter

import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.play.ballen.R
import com.play.ballen.mall.entity.MallBallInfo
import com.play.ballen.mall.ui.MallFragment
import com.yuven.appframework.util.imageloader.ImageUtil
import com.yuven.baselib.utils.ResourceUtil

class MallBallAdapter(data: MutableList<MallBallInfo>) :
    BaseQuickAdapter<MallBallInfo, BaseViewHolder>(R.layout.item_mall_ball, data) {

    var type = ""

    override fun convert(holder: BaseViewHolder, item: MallBallInfo) {

        val imgBall = holder.getView<ImageView>(R.id.imgBall)
        val tvPropertyNo = holder.getView<TextView>(R.id.tvPropertyNo)
        val tvPropertyLevel = holder.getView<TextView>(R.id.tvPropertyLevel)
        val tvPropertySport = holder.getView<TextView>(R.id.tvPropertySport)
        val tvPropertyDate = holder.getView<TextView>(R.id.tvPropertyDate)
        val tvPropertyPlayCount = holder.getView<TextView>(R.id.tvPropertyPlayCount)
        val tvPropertyPrice = holder.getView<TextView>(R.id.tvPropertyPrice)
        val llPropertyLeftCount = holder.getView<LinearLayout>(R.id.llPropertyLeftCount)
        val tvPropertyLeftCount = holder.getView<TextView>(R.id.tvPropertyLeftCount)
        val llSellCount = holder.getView<LinearLayout>(R.id.llSellCount)
        val tvSellCount = holder.getView<TextView>(R.id.tvSellCount)

        item.run {
            ImageUtil.instance.loadImage(0, 0, pic, imgBall)

            if (type == MallFragment.TYPE_MALL_OFFICIAL) {
                tvPropertyNo.visibility = View.GONE

                llPropertyLeftCount.visibility = View.VISIBLE
                tvPropertyLeftCount.text = "$remain"
                llSellCount.visibility = View.VISIBLE
                tvSellCount.text = "$selled"
            } else {
                tvPropertyNo.text = ResourceUtil.getString(R.string.home_property_no_text, no)
                tvPropertyNo.visibility = View.VISIBLE

                llPropertyLeftCount.visibility = View.GONE
                llSellCount.visibility = View.GONE
            }

            tvPropertyLevel.text = name
            tvPropertySport.text = "$percent%"
            tvPropertyDate.text = if (no != "0") {
                ResourceUtil.getString(R.string.home_property_date_forever)
            } else {
                ResourceUtil.getString(R.string.twenty_end)
            }
            tvPropertyPlayCount.text =
                ResourceUtil.getString(R.string.home_property_play_count_text, task_count)
            tvPropertyPrice.text =
                ResourceUtil.getString(
                    if (type == MallFragment.TYPE_MALL_OFFICIAL) R.string.home_property_price_text else R.string.price_unit_bmt,
                    price
                )
        }
    }

}